package com.genesis.mall.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.security.auth.login.LoginException;

@RestControllerAdvice
@Slf4j
public class ProjectException {
    @ExceptionHandler(LoginException.class)
    public Result doLoginException(Exception e){
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception e){
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    /**
     * 异常处理方法,
     * @param ex
     * @return
     */
    @ExceptionHandler(CustomException.class)
    public Result<String> exceptionHandler(CustomException ex){
        log.error(ex.getMessage());

        return  Result.error(ex.getMessage());
    }
}
